---@class ObjData : LuaObject
ObjData = BaseClass("ObjData")

---@vararg userdata
function ObjData:__ctor(...)
    local args = {...}
    self.objId = args[1]
    self.strArg = args[2]
    self.callArg = args[3]
end

---@class FaceCenter : Singleton
---@field mLuaDict table<number,IMediator>
local this = BaseClass('FaceCenter', Singleton)

function this:__ctor()
    self.mLuaDict = {}
end

function this:Awake()
    self:UpdateEvent(true)
end

function this:Destroy()
    self:UpdateEvent(false)
end

---@param isAddRem boolean
function this:UpdateEvent(isAddRem)
    LuaHelper.UpdateEvent(isAddRem, ConstData.String.OPENED_PANEL, self.OpenCView)
    LuaHelper.UpdateEvent(isAddRem, ConstData.String.CLOSE_PANEL, self.CloseCView)
end

-- 打开对话框args 参数1为提示框内容id 参数2为要替换的字符串列表 参数3为绑定按钮回掉
---@param objId number
---@param strArg string[]
---@param callArg function[]
function this:OpenDialogView(objId, strArg, callArg)
    local args = ObjData(objId, strArg, callArg)
    self:OpenView(PanelID.DialogBasePanel, args)
end

function this:CloseDialogView()
    self:CloseView(PanelID.DialogBasePanel)
end

---@param ze ZEvent
function this:OpenCView(ze)
    local param = ze.eventObj
    self:OpenView(param[1], param[2])
end

---@param ze ZEvent
function this:CloseCView(ze)
    local param = ze.eventObj
    self:CloseView(param[1])
end

---@param id number
---@param args userdata
function this:OpenView(id, args)
    local ctrl = self:GetCtrlByID(id)
    if (ctrl) then
        ctrl:SetData(args)
        MethodMgr.UIMgr_Open(ctrl.PanelId)
    end
end

function this:CloseView(id)
    local ctrl = self:GetCtrlByID(id)
    if (ctrl) then
        MethodMgr.UIMgr_Close(ctrl.PanelId)
    end
end

---@return IMediator
function this:GetCtrlByID(id)
    local ctrl = self.mLuaDict[id]
    if (not ctrl) then
        ctrl = LuaObjMgr:NewCtrlScript(id)
        self.mLuaDict[id] = ctrl
        MethodMgr.UIMgr_Register(ctrl.ClassName, id)
    end
    return ctrl
end

---@return FaceCenter
FaceCenter = this:GetInstance()